(function() {
    var a = {};
    var c = {
        handlers: {
            _guid: 0,
            getGuid: function() {
                return++this._guid
            }
        },
        find: function(e, f) {
            var h = "querySelectorAll",
            g;
            f = f || document;
            if (!f.querySelectorAll) {
                h = "getElementById";
                if (e.indexOf("#") == -1) {
                    h = "getElementsByTagName"
                } else {
                    e = e.substr(1)
                }
            }
            if (!f[h]) {
                f = document
            }
            g = f[h](e);
            return g.nodeType && !g.length ? [g] : g
        },
        event: {
            add: function(i, h, e, f, g) {
                if (document.addEventListener) {} else {
                    h = "on" + h
                }
                this._handle(i, h, e, !!f, g, "add")
            },
            remove: function(i, h, e, f, g) {
                if (document.addEventListener) {} else {
                    h = "on" + h
                }
                this._handle(i, h, e, !!f, g, "remove")
            },
            _handle: function(l, k, f, h, j, g) {
                var i = {
                    add: function(r, q, e, o) {
                        var n = c.handlers;
                        var p;
                        if (r.addEventListener) {
                            r.addEventListener(q, e, o)
                        } else {
                            if (q == "onload") {
                                r.attachEvent("onload", e)
                            } else {
                                if (! (p = r.getAttribute("data-guid-pic-ext"))) {
                                    p = c.handlers.getGuid();
                                    n[p] = {};
                                    r.setAttribute("data-guid-pic-ext", p)
                                }
                                n = n[p];
                                if (!n[q]) {
                                    n[q] = [];
                                    r[q] = function() {
                                        var t, s;
                                        try {
                                            for (t = 0, s = n[q].length; t < s; t++) {
                                                n[q][t].call(this, window.event)
                                            }
                                        } catch(u) {}
                                    }
                                }
                                n[q].push(e);
                                r = null
                            }
                        }
                    },
                    remove: function(v, r, t, u) {
                        var n = c.handlers;
                        var s;
                        if (v.removeEventListener) {
                            v.removeEventListener(r, t, u)
                        } else {
                            if (r == "onload") {
                                v.detachEvent("onload", t)
                            } else {
                                s = v.getAttribute("data-guid-pic-ext");
                                n = n[s];
                                for (var o = 0,
                                p = n[r].length; o < p; o++) {
                                    if (n[r][o] == t) {
                                        n[r].splice(o, 1)
                                    }
                                }
                                if (!n.length) {
                                    try {
                                        delete c.handlers[s][r];
                                        delete v[r];
                                        v[r] = null
                                    } catch(q) {
                                        c.handlers[s][r] = null;
                                        v[r] = null
                                    }
                                }
                            }
                        }
                    }
                };
                if (typeof l == "string") {
                    l = c.find(l, j);
                    if (l.length > 0) {
                        c.forEach(l,
                        function(e) {
                            i[g](e, k, f, h)
                        })
                    }
                } else {
                    try {
                        i[g](l, k, f, h)
                    } catch(m) {}
                }
            },
            preventDefault: function(f) {
                if (f.preventDefault) {
                    f.preventDefault()
                } else {
                    f.returnValue = false
                }
            },
            target: function(f) {
                return f.target || f.srcElement
            },
            getRelatedTarget: function(f) {
                if (f.relatedTarget) {
                    return f.relatedTarget
                } else {
                    if (f.toElement) {
                        return f.toElement
                    } else {
                        if (f.fromElement) {
                            return f.fromElement
                        } else {
                            return null
                        }
                    }
                }
            },
            stop: function(e) {
                if (!e) {
                    return false
                }
                if (e.preventDefault) {
                    e.preventDefault();
                    e.stopPropagation()
                } else {
                    e.returnValue = false;
                    e.cancelBubble = false
                }
            }
        },
        dimension: {
            minSize: 300,
            defaultMinSize: 300,
            validCls: "pic-valid-selected-img",
            originalImg: new Image(),
            verify: function(e) {
                if (e.src) {
                    this.originalImg.src = e.src;
                    if (e.className.indexOf(this.validCls) > -1) {
                        return true
                    } else {
                        if (this.originalImg.width >= this.minSize && this.originalImg.height >= this.minSize) {
                            e.className += " " + this.validCls;
                            return true
                        } else {
                            return false
                        }
                    }
                }
            },
            setMinSize: function(e) {
                if (typeof e == "number" && e > this.defaultMinSize && this.minSize != e) {
                    this.minSize = e
                }
                return this
            }
        },
        format: function(f, e) {
            return f.replace(/#\{(.+?)\}/g,
            function(g, i) {
                var h = e[i];
                return ("undefined" == typeof h ? "": h)
            });
            return f
        },
        getView: function() {
            var f = document,
            e = f.compatMode == "BackCompat" ? f.body: f.documentElement;
            return {
                w: e.clientWidth,
                h: e.clientHeight,
                st: window.pageYOffset || f.documentElement.scrollTop || f.body.scrollTop,
                sl: window.pageXOffset || f.documentElement.scrollLeft || f.body.scrollLeft
            }
        },
        getPosition: function(l) {
            var m = 0,
            v = 0;
            if (l.getBoundingClientRect) {
                var u = window,
                t = document.body,
                s = document.documentElement,
                r = l.getBoundingClientRect(),
                q = s.clientTop || t.clientTop || 0,
                p = s.clientLeft || t.clientLeft || 0,
                o = u.pageYOffset || t.scrollTop || s.scrollTop,
                n = u.pageXOffset || t.scrollLeft || s.scrollLeft;
                m = r.left + n - p,
                v = r.top + o - q
            }
            return {
                left: m,
                top: v,
                width: l.width,
                height: l.height
            }
        },
        keys: (function() {
            var g = Object.prototype.hasOwnProperty,
            h = !({
                toString: null
            }).propertyIsEnumerable("toString"),
            f = ["toString", "toLocaleString", "valueOf", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable", "constructor"],
            e = f.length;
            return function(l) {
                if (typeof l !== "object" && typeof l !== "function" || l === null) {
                    throw new TypeError("Object.keys called on non-object")
                }
                var j = [];
                for (var m in l) {
                    if (g.call(l, m)) {
                        j.push(m)
                    }
                }
                if (h) {
                    for (var k = 0; k < e; k++) {
                        if (g.call(l, f[k])) {
                            j.push(f[k])
                        }
                    }
                }
                return j
            }
        })(),
        forEach: function(o, p) {
            var f, g;
            if (this == null) {
                throw new TypeError("this is null or not defined")
            }
            var l = o,
            j;
            var m = l.length >>> 0;
            if (o.forEach) {
                o.forEach(p);
                return
            } else {
                if (Object.prototype.toString(o) !== "[object Array]") {
                    try {
                        l = Array.prototype.slice.call(o)
                    } catch(n) {
                        o = [];
                        for (j = 0; j < m; j++) {
                            o.push(l[j])
                        }
                        l = o
                    }
                }
            }
            if ({}.toString.call(p) !== "[object Function]") {
                throw new TypeError(p + " is not a function")
            }
            if (o) {
                f = o
            }
            g = 0;
            while (g < m) {
                var h;
                if (Object.prototype.hasOwnProperty.call(l, g)) {
                    h = l[g];
                    p.call(f, h, g, l)
                }
                g++
            }
        },
        mixin: function(f, e) {
            function g(i, h) {
                if (!f[i]) {
                    f[i] = e[i]
                }
            }
            c.forEach(c.keys(e),
            function(i, h) {
                g(i, h)
            })
        },
        indexOf: function(i, g) {
            if (this == null) {
                throw new TypeError()
            }
            var h = i;
            var e = h.length >>> 0;
            if (e === 0) {
                return - 1
            }
            var j = 0;
            if (arguments.length > 1) {
                j = Number(arguments[2]);
                if (j != j) {
                    j = 0
                } else {
                    if (j != 0 && j != Infinity && j != -Infinity) {
                        j = (j > 0 || -1) * Math.floor(Math.abs(j))
                    }
                }
            }
            if (j >= e) {
                return - 1
            }
            var f = j >= 0 ? j: Math.max(e - Math.abs(j), 0);
            for (; f < e; f++) {
                if (f in h && h[f] === g) {
                    return f
                }
            }
            return - 1
        }
    };
    var b = {
        _listeners: {},
        addEventListener: function(e, f) {
            if (typeof f != "function") {
                return this
            }
            if (!this._listeners[e]) {
                this._listeners[e] = []
            }
            this._listeners[e].push(f);
            return this
        },
        removeEventListener: function(g, h) {
            var f = this._listeners[g],
            e;
            if (!f) {
                return this
            }
            e = c.indexOf(f, h);
            if (e > -1) {
                f.splice(e, 1)
            }
            return this
        },
        dispatchEvent: function(h) {
            var i = this,
            f = Array.prototype.slice.call(arguments, 1),
            g = this._listeners[h],
            e;
            if (!g) {
                return this
            }
            function e(j) {
                j.apply(i, f)
            }
            c.forEach(g, e);
            return this
        }
    }; (function(e, g) {
        var f = {
            isInit: false,
            fragment: null,
            hideBtnTimer: null,
            bodyListenerFlag: false,
            currentURL: "",
            createView: function() {
                var h = document.createElement("div");
                h.id = "pic_ext_float";
                h.innerHTML = '<div id="pic_ext_float_btn"><a href="#" class="pic_ext_float_btn_a" onclick="return false;"><span id="pic_ext_float_btn_t">收藏到百度相册</span></a></div>';
                document.body.appendChild(h);
                this.fragment = h;
                this.bindEvent()
            },
            bindEvent: function() {
                var h = this;
                g.event.add(this.fragment, "mouseover",
                function(i) {
                    var j = this;
                    g.event.remove(document.body, "mouseover", h.bodyListenerHandler);
                    h.bodyListenerFlag = false;
                    if (h.hideBtnTimer) {
                        clearTimeout(h.hideBtnTimer)
                    }
                    j.style.display = "block"
                });
                g.event.add(this.fragment, "mouseout",
                function(i) {
                    h.hideFloatBtn();
                    if (h.bodyListenerFlag == false) {
                        g.event.add(document.body, "mouseover", h.bodyListenerHandler);
                        h.bodyListenerFlag = true
                    }
                });
                g.event.add(this.fragment, "click",
                function(i) {
                    h.dispatchEvent("clicked", {
                        currentURL: h.currentURL
                    });
                    g.event.preventDefault(i)
                })
            },
            bodyListenerHandler: function(k) {
                var j = g.event.target(k),
                m = j.nodeName.toUpperCase(),
                i = j.className,
                l,
                h;
                if (m == "IMG") {
                    if (g.dimension.verify(j)) {
                        l = g.getPosition(j);
                        if (f.hideBtnTimer) {
                            clearTimeout(f.hideBtnTimer)
                        }
                        f.fragment.style.display = "block";
                        f.fragment.style.left = l.left + l.width - 127 + "px";
                        f.fragment.style.top = l.top - 29 + "px";
                        f.currentURL = j.src;
                        if (!document.body.lastElementChild || document.body.lastElementChild != f.fragment) {
                            document.body.appendChild(f.fragment)
                        }
                    }
                } else {
                    f.hideFloatBtn()
                }
            },
            hideFloatBtnAction: function() {
                f.fragment.style.display = "none"
            },
            hideFloatBtn: function() {
                if (f.hideBtnTimer) {
                    clearTimeout(f.hideBtnTimer)
                }
                f.hideBtnTimer = setTimeout(this.hideFloatBtnAction, 500)
            },
            init: function() {
                f.createView();
                this.isInit = true
            },
            enable: function() {
                if (!this.isInit) {
                    this.init()
                }
                g.event.add(document.body, "mouseover", this.bodyListenerHandler);
                this.bodyListenerFlag = true;
                return this
            },
            disable: function() {
                if (this.hideBtnTimer) {
                    clearTimeout(this.hideBtnTimer);
                    this.hideFloatBtnAction()
                }
                if (!this.bodyListenerFlag) {
                    return this
                }
                g.event.remove(document.body, "mouseover", this.bodyListenerHandler);
                this.bodyListenerFlag = false
            }
        };
        e.floatBtn = f;
        g.mixin(f, b)
    })(a, c); (function(f, g) {
        var e = {
            remainImgSources: null,
            baseUrl: "http://xiangce.baidu.com/bookmark",
            fragment: null,
            visible: true,
            dataToBeSent: null,
            state: 0,
            windowName: null,
            sendData: function(h) {
                this.dataToBeSent = this.buildData(h);
                this.createIframe()
            },
            buildData: function(j) {
                var k, l, h = {
                    tpl: "v3",
                    name: document.title || "",
                    surl: location.href,
                    srcs: []
                };
                for (k = 0; l = j[k]; k++) {
                    h.srcs.push(l)
                }
                return h
            },
            generateUrl: function() {
                var h = this.baseUrl + (this.baseUrl.indexOf("?") == -1 ? "?": ""),
                l = ["tpl", "name", "surl"],
                k,
                j = 0;
                for (; k = l[j]; j++) {
                    if (j) {
                        h += "&"
                    }
                    h += k + "=" + encodeURIComponent(this.dataToBeSent[k])
                }
                return h
            },
            createIframe: function() {
                var h = document.createElement("div"),
                j = this.generateUrl();
                h.style.width = "650px";
                h.style.height = "350px";
                h.id = "pic_ext_faviframe_con";
                h.innerHTML = '<iframe id="pic_ext_faviframe" src="' + j + '" frameBorder="0" scrolling="no" border="0"  width="200px" height="200px""></iframe>';
                this.fragment = h;
                this.dispatchEvent("sendDataStart");
                var i = g.find("#pic_ext_faviframe", h)[0];
                if (!window.postMessage) {
                    i.contentWindow.name = e.formatData("imagedata", e.dataToBeSent.srcs);
                    this.state = 0;
                    this.windowName = window.name;
                    g.event.add(i, "load", this.oldBrowserCloseWindowListener, false)
                }
                g.event.add(i, "load", this.frameOnload, false)
            },
            frameOnload: function(h) {
                var k = g.event.target(h),
                j = e.formatData("imagedata", e.dataToBeSent.srcs),
                i = j;
                if (k.contentWindow.postMessage) {
                    k.contentWindow.postMessage(j, "*");
                    e.dataToBeSent = null
                }
                e.dispatchEvent("sendDataReady");
                g.event.remove(k, "load", e.frameOnload)
            },
            oldBrowserCloseWindowListener: function(h) {
                var i;
                if (window.name == "closeWindow") {
                    i = g.event.target(h);
                    g.event.remove(i, "load", e.oldBrowserCloseWindowListener);
                    e.state = 0;
                    e.dispatchEvent("closeWindow")
                }
                e.state++
            },
            formatData: function(h, i) {
                var k = [];
                for (var j in i) {
                    if (i.hasOwnProperty(j)) {
                        if (/[\"\']/.test(i[j])) {
                            k.push(i[j])
                        } else {
                            k.push('"' + i[j] + '"')
                        }
                    }
                }
                return '{"type": "' + h + '","srcs": [' + k + "]}"
            },
            appendTo: function(h) {
                if (!h.appendChild) {
                    return
                }
                h.appendChild(this.fragment)
            },
            clean: function() {
                if (!this.fragment) {
                    return
                }
                if (window.name) {
                    window.name = this.windowName;
                    this.windowName = ""
                }
                this.onloadFlag = 0;
                this.remainImgSources = null;
                this.fragment.parentNode.removeChild(this.fragment);
                this.fragment = null;
                this.visible = true
            },
            show: function() {
                this._setVisible(true)
            },
            hide: function() {
                this._setVisible(false)
            },
            _setVisible: function(h) {
                if (this.visible != h) {
                    this.visible = h;
                    this.fragment.className = h ? "": "hide"
                }
            }
        };
        f.sendController = e;
        g.mixin(e, b)
    })(a, c); (function(f, g) {
        var e = {
            overlayEl: null,
            contentHolder: null,
            isInit: false,
            createOverLay: function() {
                var i = document.createElement("div");
                i.id = "pic_ext_overlay";
                var h = document.createElement("div");
                h.id = "pic_ext_favWindow";
                h.innerHTML = "<span id='pic_ext_frameloading'>正在加载....</span><a href='#' id='close_fav_window'></a>";
                document.body.appendChild(i);
                document.body.appendChild(h);
                this.overlayEl = i;
                this.contentHolder = h;
                g.event.add("#close_fav_window", "click", this.closeFavWindow, false);
                this.isInit = true
            },
            closeFavWindow: function(h) {
                g.event.preventDefault(h);
                e.hide();
                return false
            },
            show: function(h) {
                if (!this.isInit) {
                    this.createOverLay()
                }
                this.overlayEl.style.display = "block";
                this.contentHolder.style.display = h ? "none": "block";
                this.dispatchEvent("showOverlay")
            },
            hide: function() {
                this.overlayEl.style.display = "none";
                this.contentHolder.style.display = "none";
                e.dispatchEvent("closeOverlay")
            },
            hideLoading: function() {
                this.contentHolder.className = ""
            },
            showLoading: function() {
                this.contentHolder.className = "loading"
            }
        };
        f.overlay = e;
        g.mixin(e, b)
    })(a, c); (function(f, g) {
        var e = {
            view: null,
            isInit: false,
            minSize: 300,
            images: null,
            selectedNum: 0,
            selItems: [],
            createContent: function() {
                var o = '<div id="pic_ext_controll_inner"><ul id="pic_ext_list">';
                var l = [];
                var p = ['<li style="#{marLeft}" data-index="#{index}" data-select="0">', '<img class="pic_ext_tile_img" style="top:#{top}px;left:#{left}px;" src="#{src}" width="#{rw}" height="#{rh}" />', '<p class="pic_ext_tile_size_wrap"><span class="pic_ext_tile_size">#{w}x#{h}</span></p>', '<div class="pic_ext_tile_super">', '<div class="pic_ext_img-lay"></div>', '<div class="pic_ext_select_logo"></div>', '<a onclick="return false" class="pic_ext_img_select" href=""></a>', '<a onclick="return false" class="pic_ext_img_cancle" href=""></a>', "</div>", "</li>"].join("");
                var k = ['</ul><p id="less_than12">温馨提示：您目前设置的是最小尺寸是', this.minSize, '以上的图片哦 ^_^</p><div style="clear:both;"></div></div>'].join("");
                for (var m = 0,
                j = this.images,
                h = j.length; m < h; m++) {
                    if (m % 4 == 0) {
                        j[m]["marLeft"] = "margin-left:0"
                    }
                    j[m].index = m;
                    l.push(g.format(p, j[m]))
                }
                var n = document.createElement("div");
                n.id = "pic_ext_controll";
                n.innerHTML = o + l.join("") + k;
                document.body.appendChild(n);
                this.view = n;
                g.find("#less_than12")[0].style.display = j.length <= 12 ? "block": "none";
                g.event.add("li", "click", this.clickHandler, false, this.view);
                g.event.add("li", "mouseover", this.mouseoverHandler, false, this.view);
                g.event.add("li", "mouseout", this.mouseoutHandler, false, this.view);
                document.body.scrollTop = 0;
                this.isInit = true;
                this.dispatchEvent("contentShow", {
                    imgNum: j.length
                })
            },
            getImages: function() {
                var q = [];
                function j(s) {
                    var u = {};
                    var i = s.src;
                    var y = s.width;
                    var t = s.height;
                    var o, x, v, r;
                    if (y / t > 1) {
                        x = 198;
                        o = (x * y) / t
                    } else {
                        if (y / t == 1) {
                            x = 198;
                            o = 198
                        } else {
                            o = 198;
                            x = (o * t) / y
                        }
                    }
                    v = 99 - (x / 2) || 0;
                    r = 99 - (o / 2) || 0;
                    return {
                        w: s.width,
                        h: s.height,
                        src: i,
                        alt: s.alt || "",
                        orig: s,
                        rw: o,
                        rh: x,
                        top: v,
                        left: r
                    }
                }
                function n(v) {
                    var s = v.images,
                    u = {};
                    for (var r = 0,
                    w, t; w = s[r++];) {
                        if (w.style.display != "none") {
                            if (w.complete) {
                                u = new Image();
                                u.src = w.src;
                                t = j(u);
                                if (g.dimension.verify(w)) {
                                    if (t.src) {
                                        w.setAttribute("dataxc-width", t.w);
                                        w.setAttribute("dataxc-height", t.h);
                                        q.push(t)
                                    }
                                }
                            }
                        }
                    }
                }
                n(document);
                var m = document.getElementsByTagName("iframe");
                for (var h = 0,
                p; p = m[h++];) {
                    try {
                        var l = p.contentDocument;
                        l && n(l)
                    } catch(k) {}
                }
                this.images = q
            },
            clickHandler: function(h) {
                e.previewSelect(this)
            },
            mouseoverHandler: function(i) {
                var h = i.relatedTarget;
                if (!h || (!(h.compareDocumentPosition(this) & 8) && h !== this)) {
                    e.enter.call(this, i)
                }
            },
            mouseoutHandler: function(i) {
                var h = i.relatedTarget;
                if (!h || (!(h.compareDocumentPosition(this) & 8) && h !== this)) {
                    e.leave.call(this, i)
                }
            },
            show: function() {
                if (!this.isInit) {
                    this.getImages();
                    this.createContent()
                }
            },
            enter: function(j) {
                var i = this.getAttribute("data-select");
                var h = this.getElementsByTagName("a");
                if (i == 1) {
                    h[0].style.display = "none";
                    h[1].style.display = "inline-block"
                } else {
                    h[0].style.display = "inline-block";
                    h[1].style.display = "none";
                    this.getElementsByTagName("div")[1].style.display = "block"
                }
            },
            leave: function(j) {
                var i = this.getAttribute("data-select");
                var h = this.getElementsByTagName("a");
                h[0].style.display = "none";
                h[1].style.display = "none";
                if (i != "1") {
                    this.getElementsByTagName("div")[1].style.display = "none"
                }
            },
            hide: function() {
                if (this.view) {
                    g.event.remove("li", "click", this.clickHandler, false, this.view);
                    g.event.remove("li", "mouseover", this.mouseoverHandler, false, this.view);
                    g.event.remove("li", "mouseout", this.mouseoutHandler, false, this.view);
                    this.view.parentNode.removeChild(this.view);
                    this.images = null;
                    this.isInit = false;
                    this.selItems = [];
                    this.selectedNum = 0
                }
            },
            setMinSize: function(h) {
                if (typeof h == "number" && h > 100 && h != this.minSize) {
                    this.minSize = h
                }
            },
            previewSelect: function(o, m) {
                var h = o.getAttribute("data-select");
                var j = 500;
                var q;
                var r;
                q = o.getAttribute("data-index");
                if (m == "all" || (!m && h == "0")) {
                    if (this.selItems.length >= j) {
                        alert("最多只能选" + j + "张图片哦~");
                        return false
                    }
                    o.setAttribute("data-select", "1");
                    r = o.getElementsByTagName("div");
                    for (var p = 0,
                    k = r.length; p < k; p++) {
                        if (r[p].className && (r[p].className == "pic_ext_img-lay" || r[p].className == "pic_ext_select_logo")) {
                            r[p].style.display = "block"
                        }
                    }
                    o.style.borderColor = "#1aa8f5";
                    if (!m) {
                        this.selItems.push(q);
                        this.updateSelItem("add")
                    }
                } else {
                    r = o.getElementsByTagName("div");
                    for (var p = 0,
                    k = r.length; p < k; p++) {
                        if (r[p].className && (r[p].className == "pic_ext_img-lay" || r[p].className == "pic_ext_select_logo")) {
                            r[p].style.display = "none"
                        }
                    }
                    o.setAttribute("data-select", "0");
                    o.style.borderColor = "#fff";
                    if (!m) {
                        if ((p = c.indexOf(this.selItems, q)) > -1) {
                            this.selItems.splice(p, 1);
                            this.updateSelItem("remove")
                        }
                    }
                }
                var n = o.getElementsByTagName("a");
                n[0].style.display = "none";
                n[1].style.display = "none"
            },
            previewSelectAll: function() {
                g.forEach(g.find("li", this.view),
                function(h) {
                    e.previewSelect(h, "all")
                });
                this.selItems = c.keys(this.images);
                this.updateSelItem("all")
            },
            previewSelectNone: function() {
                c.forEach(g.find("li", this.view),
                function(h) {
                    e.previewSelect(h, "none")
                });
                this.selItems = [];
                this.updateSelItem("none")
            },
            updateSelItem: function(h) {
                switch (h) {
                case "remove":
                    this.selectedNum--;
                    break;
                case "add":
                    this.selectedNum++;
                    break;
                case "all":
                    this.selectedNum = this.images.length;
                    break;
                case "none":
                    this.selectedNum = 0;
                    break
                }
                this.dispatchEvent("updateSelItem", {
                    selectedNum: this.selectedNum,
                    totalNum: this.images.length
                })
            },
            getSelImagesSource: function() {
                var h = [];
                c.forEach(this.selItems,
                function(i) {
                    h.push(e.images[i].src)
                });
                return h
            }
        };
        f.contentCtrl = e;
        g.mixin(e, b)
    })(a, c); (function(e, f) {
        var g = {
            isInit: false,
            fragment: null,
            selectedItem: 0,
            isSelectAll: false,
            createTopBar: function() {
                var h = ['<div id="pic_ext_bar_inner">', '<img id="pic_ext_logo" src="http://xiangce.baidu.com/static/images/bdXC-logo.png">', '<a id="pic_ext_fav_button" href="#" ></a>', '<span id="pic_ext_fav_tips">已选择<span id="pic_ext_fav_num_current">0</span>张图片 <input id="pic_ext_selectAll" type="checkbox" /> 全选</span>', '<a id="pic_ext_close" href="#"></a>', "</div>"];
                var i = document.createElement("div");
                i.id = "pic_ext_bar";
                i.innerHTML = h.join("");
                document.body.appendChild(i);
                f.event.add("#pic_ext_selectAll", "click",
                function(k) {
                    var j = f.event.target(k);
                    g.selectAll(j.checked)
                },
                false);
                f.event.add("#pic_ext_fav_button", "click", this.submitBtnHandler, false);
                f.event.add("#pic_ext_close", "click", this.cancelBtnHandler, false);
                this.fragment = i;
                this.isInit = true
            },
            selectAll: function(i, h) {
                if (!h) {
                    this.dispatchEvent("selectAll", {
                        select: i
                    })
                } else {
                    f.find("#pic_ext_selectAll")[0].checked = i
                }
                this.isSelectAll = i
            },
            show: function() {
                if (!this.isInit) {
                    this.createTopBar()
                }
                this.fragment.style.display = "block"
            },
            hide: function() {
                if (this.isInit) {
                    this.updateSelectedItem(0);
                    this.selectAll(false, true);
                    this.fragment.style.display = "none"
                }
            },
            submitBtnHandler: function(h) {
                f.event.preventDefault(h);
                if (g.selectedItem) {
                    g.dispatchEvent("submitItem")
                }
            },
            cancelBtnHandler: function(h) {
                f.event.preventDefault(h);
                g.dispatchEvent("topBarClose")
            },
            updateSelectedItem: function(j, i) {
                var h = f.find("#pic_ext_fav_button", this.fragment)[0];
                if (j > 0 && this.selectedItem == 0) {
                    h.className = "pic_ext_fav_button_select"
                } else {
                    if (j <= 0 && this.selectedItem > 0) {
                        h.className = ""
                    }
                }
                f.find("#pic_ext_fav_num_current")[0].innerHTML = encodeURIComponent(j);
                this.selectedItem = j;
                if (j != i && this.isSelectAll) {
                    this.selectAll(false, true)
                } else {
                    if (j == i && !this.isSelectAll) {
                        this.selectAll(true, true)
                    }
                }
            }
        };
        e.topBar = g;
        f.mixin(g, b)
    })(a, c);
    var d = {
        disableMsg: {
            1 : "你在自己的相册，不能收藏自己的图片哦！"
        },
        active: false,
        collectable: true,
        overlayShow: false,
        isInit: false,
        disable: 0,
        isFloatBtnEnable: false,
        restrictSites: ["tieba.baidu.com", "image.baidu.com"],
        xiangceHost: "http://xiangce.baidu.com",
        hostname: "xiangce.baidu.com",
        styleSheet: {
            bdXC_style_text: "#pic_ext_overlay{background-color: #000;  opacity: 0.7;  width:100%;height:100%;filter: alpha(opacity=70);position:fixed;left:0;z-index:2147483645;top:0;_position:absolute !important;_bottom:auto !important;_top:expression(eval(document.documentElement.scrollTop))!important;}                            body{_background-image:url(about:blank);_background-attachment:fixed;_height:100%!important;}                            #pic_ext_logo{display:'';}                            #pic_ext_bar{height:50px;background-color:#f8f9f8;opacity:1;z-index:2147483647;position:fixed;left:0;top:0;width:100%;margin:0;padding:0;text-align:center;_position:absolute !important;_bottom:auto !important;_top:expression(eval(document.documentElement.scrollTop))!important;}                            #pic_ext_fav_button{display:inline-block;width:143px;height:30px;position:absolute;left:612px;top:12px;background:url(http://xiangce.baidu.com/static/images/bdXC_fav_button_cancle.png) 0 0 no-repeat;cursor:default;}                            .pic_ext_fav_button_select{background-position:0 -39px!important;cursor:pointer !important;}                            .pic_ext_fav_button_select:hover{background-position:0 -80px!important;}                            #pic_ext_bar_inner{width:830px;padding-top:10px;position:relative;margin-left:auto;margin-right:auto;text-align:left;}                            #pic_ext_close{display:inline-block;height:30px;width:67px;position:absolute;right:0;top:12px;background:url(http://xiangce.baidu.com/static/images/bdXC_fav_button_cancle.png) -153px -39px no-repeat;}                            #pic_ext_close:hover{background-position:-153px -80px;}                            #pic_ext_fav_tips{font-size:12px;color:#999;position:absolute;top:19px;right: 235px;}                            #less_than12{clear:both;text-align:center;color:#fff;padding-top:100px;font-size:14px;display:none;}                            #pic_ext_fav_num_current,#pic_ext_fav_num_total{color:#ff6600;font-family: arial;font-weight: bold;}                            #pic_ext_selectAll{vertical-align: middle;margin:0;margin-top:-1px;}                            #pic_ext_controll{text-algin:center;position:absolute;width:100%;left:0;top:50px;z-index:2147483646;}                            #pic_ext_controll_inner{text-align:left;width:830px;margin-left:auto;margin-right:auto;}                            #pic_ext_controll_inner ul{margin:0;padding:0;}                            #pic_ext_controll_inner li{_display:inline;text-align: center;overflow:hidden;background-color:#fff;list-style:none;margin:0;padding:0;width:198px;height:198px;border:1px solid #fff;float:left;margin-top:10px;margin-left:10px;position:relative;cursor:pointer;}                            .pic_ext_tile_img{position:absolute;}#pic_ext_controll_inner li.pic_ext_selected{border-color:#1aa8f5;}                            #pic_ext_controll_inner li.pic_ext_tile_over .pic_ext_img-lay{display:block;}                            .pic_ext_tile_over .pic_ext_img_select{display:inline-block;}                            .pic_ext_img-lay{position:absolute;width:198px;height:198px;background-color:#000;opacity:0.60;filter: alpha(opacity=60);left:0px;top:0px;display:none;}                            .pic_ext_img_select,.pic_ext_img_cancle{display:none;width:75px;height:33px;position:absolute;left:65px;top:85px;background:url(http://xiangce.baidu.com/static/images/bdXC_operate_btn.png) no-repeat -81px 0;cursor:pointer;}                            .pic_ext_img_select:hover{background:url(http://xiangce.baidu.com/static/images/bdXC_operate_btn.png) no-repeat -81px -37px;}                            .pic_ext_img_cancle{display:none;background:url(http://xiangce.baidu.com/static/images/bdXC_operate_btn.png) no-repeat 0 0;}                            .pic_ext_img_cancle:hover{background:url(http://xiangce.baidu.com/static/images/bdXC_operate_btn.png) no-repeat 0 -37px;}                            .pic_ext_tile_size_wrap{position:absolute;top:170px;left:0;text-align: center;margin:0;padding:0;width:198px;}                            .pic_ext_tile_size{display:inline-block;background-color:#333;padding:2px 4px 2px 4px;font-size:12px;color:#fff;font-family: arial;}                            .pic_ext_select_logo{position:absolute;top:75px;left:70px;width:70px;height:48px;display:none;background:url(http://xiangce.baidu.com/static/images/bdXC_select_logo.png) no-repeat;_background: none;_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://xiangce.baidu.com/static/images/bdXC_select_logo.png',sizingMethod='crop');}                            #pic_ext_float_btn{width:123px;padding-left:5px;background: url(http://xiangce.baidu.com/static/images/xiangce_ext_floatbtn_bg.png) no-repeat;}                            .pic_ext_float_btn_a{background-color:transparent;display: inline-block;cursor: pointer;color: #666;text-decoration: none;}                            #pic_ext_float_btn_t{display:inline-block; line-height:16px; padding:8px 0 8px 30px;font:12px '宋体' !important;color:#fff;}                            #pic_ext_float_btn:hover{text-decoration:none; background-image: url(http://xiangce.baidu.com/static/images/xiangce_ext_floatbtn_bg_hover.png);}                            #pic_ext_float_btn:hover .pic_ext_float_btn_l{background-position:-28px 4px;}                            #pic_ext_float{display:none;position: absolute;left: 0;top:0;z-index:2147483644;cursor: pointer;}                            #pic_ext_favWindow{display:none;position:fixed;_position:absolute;width:650px;height:350px;z-index:2147483646;background-color:#fff;left: 50%;top: 50%;margin-left: -325px;margin-top: -175px;}                            #close_fav_window{width:11px;height:11px;_font-size:0;position:absolute;background:url(http://xiangce.baidu.com/static/images/bdXC_closeWindow.png);position:absolute;left:620px;top:15px;}                            #frameloading{position:absolute;top:150px;left:280px;color:#666;}                            #pic_ext_faviframe{width:650px;height:350px;border:none;}                            .pic_ext_float_btn_a,.pic_ext_float_btn_a:visited,.pic_ext_float_btn_a:hover,.pic_ext_float_btn_a:active{background-color:transparent;text-decoration: none;}                            #pic_ext_favWindow.loading #close_fav_window{display: none;}#pic_ext_frameloading {display: none;position:absolute;top:150px;left:280px;color:#666;}#pic_ext_favWindow.loading #pic_ext_frameloading{display: block;}",
            addStyle: function() {
                var e = document.createElement("style");
                e.type = "text/css";
                e.media = "screen";
                e.styleSheet ? (e.styleSheet.cssText = this.bdXC_style_text) : e.appendChild(document.createTextNode(this.bdXC_style_text)); (document.getElementsByTagName("head")[0] || document.body).appendChild(e)
            }
        },
        init: function() {
            var k, f, i, h, l, g;
            if (window.addEventListener) {
                l = "addEventListener"
            } else {
                if (window.attachEvent) {
                    l = "attachEvent"
                } else {
                    l = "blank_func_test";
                    window[l] = Function.prototype
                }
            }
            try {
                h = document.getElementsByTagName("head")[0] || document.getElementsByTagName("script")[0].parentNode
            } catch(j) {
                h = document.body
            }
            if (window.postMessage) {
                if (!window.JSON) {}
                g = l == "addEventListener" ? "message": "onmessage";
                window[l](g, this.checkIsSelf, false);
                window[l](g, this.runByBookmarklet, false);
                window[l](g, this.closeWindowListner, false)
            }
            this.styleSheet.addStyle();
            this.bindEvent();
            if (c.indexOf(d.restrictSites, location.hostname) == -1) {
                a.floatBtn.enable();
                d.isFloatBtnEnable = true
            }
            if (location.hostname == this.hostname) {
                if (window.pic && window.pic.owner && window.pic.owner.is_self && window.location.href.indexOf("/square") == -1 && window.location.href.indexOf("/feed/") == -1) {
                    d.disable = 1;
                    a.floatBtn.disable();
                    d.isFloatBtnEnable = false
                }
            }
        },
        closeWindowListner: function(e) {
            if (e.origin == d.xiangceHost) {
                if (e.data == "closeWindow" || (e.data && e.data.type == "closeWindow")) {
                    d.closeOverlay()
                }
            }
        },
        checkIsSelf: function(f) {
            var g;
            try {
                g = JSON.parse(f.data)
            } catch(h) {
                g = f.data
            }
            if (g && g.type === "detect") {
                if (g.isSelf) {
                    d.disable = 1;
                    a.floatBtn.disable();
                    d.isFloatBtnEnable = false
                }
                if (window.removeEventListener) {
                    window.removeEventListener("message", d.checkIsSelf)
                } else {
                    if (window.detachEvent) {
                        window.detachEvent("onmessage", d.checkIsSelf)
                    }
                }
            }
        },
        runByBookmarklet: function(f) {
            var g;
            try {
                g = JSON.parse(f.data)
            } catch(h) {
                g = f.data
            }
            if (g && g.type === "bookmarklet" && g.reInit) {
                d.showImagePicker()
            }
        },
        overlayShowed: function() {
            d.overlayShow = true;
            if (d.isFloatBtnEnable) {
                a.floatBtn.disable()
            }
        },
        overlayClosed: function() {
            a.sendController.clean();
            d.overlayShow = false;
            if (d.isFloatBtnEnable) {
                a.floatBtn.enable()
            }
        },
        closeOverlay: function() {
            a.overlay.hide()
        },
        floatBtnClicked: function(e) {
            a.sendController.sendData([e.currentURL])
        },
        sendDataStart: function() {
            a.sendController.hide();
            a.overlay.show();
            a.overlay.showLoading();
            a.sendController.appendTo(a.overlay.contentHolder)
        },
        sendDataReady: function() {
            a.sendController.show();
            a.overlay.hideLoading()
        },
        showImagePicker: function() {
            if (!this.checkIsAvailable() || this.overlayShow) {
                return
            }
            a.overlay.show(true);
            a.topBar.show();
            a.contentCtrl.show()
        },
        checkIsAvailable: function() {
            if (this.disable) {
                alert(this.disableMsg[this.disable]);
                return false
            }
            return true
        },
        closeImagePicker: function() {
            a.overlay.hide();
            a.topBar.hide();
            a.contentCtrl.hide()
        },
        bindEvent: function() {
            a.floatBtn.addEventListener("clicked", this.floatBtnClicked);
            a.sendController.addEventListener("sendDataStart", this.sendDataStart);
            a.sendController.addEventListener("sendDataReady", this.sendDataReady);
            a.overlay.addEventListener("showOverlay", this.overlayShowed);
            a.overlay.addEventListener("closeOverlay", this.overlayClosed);
            a.topBar.addEventListener("selectAll",
            function(e) {
                if (e.select == true) {
                    a.contentCtrl.previewSelectAll()
                } else {
                    a.contentCtrl.previewSelectNone()
                }
            });
            a.contentCtrl.addEventListener("updateSelItem",
            function(e) {
                a.topBar.updateSelectedItem(e.selectedNum, e.totalNum)
            });
            a.contentCtrl.addEventListener("contentShow",
            function(e) {
                if (e.imgNum == 0) {
                    d.closeImagePicker();
                    alert("没有合适的图片")
                }
            });
            a.topBar.addEventListener("submitItem",
            function() {
                a.sendController.sendData(a.contentCtrl.getSelImagesSource());
                this.hide();
                a.contentCtrl.hide()
            });
            a.topBar.addEventListener("topBarClose", d.closeImagePicker);
            if (!window.postMessage) {
                a.sendController.addEventListener("closeWindow",
                function() {
                    d.closeOverlay()
                })
            }
        }
    };
    d.init(); (function() {
        window._bdXC_loaded = true;
        window._bdXC = {
            reInit: function() {
                d.showImagePicker()
            },
            init: function() {
                d.showImagePicker()
            }
        }
    })();
    window._bdXC.init()
})();